<?php
class Control_Column extends QUI_Control_Abstract {
    function render() {
        //        dump($this->_attrs);
        $categories = Column::find('parent_id = 0')->all()->query();
        $str = '<select';
        if(!empty($this->_attrs)) {
            foreach($this->_attrs as $key=>$value) {
                $str .= ' '. $key . '="' .$value.'"';
            }
        }

        $str .= '>';
        $str .= '<option value="0">------无------</option>';

        foreach($categories as $category) {
            $cate = Helper_Common::getFormCache(null, 'Column', $category->col_id);
//                        dump($cate);
            $cs = null;
            //            $key++;
            FUNC::getChildren($cate, $cs, array('col_id', 'name'));    //查找孩子
            //            dump($cs);
            if($this->_attrs['selected'] == $category->col_id) {
                $str .= '<option selected="selected" value="'.$category->col_id.'">' .$category->name. '</option>';
            }
            else {
                $str .= '<option value="'.$category->col_id.'">' .$category->name. '</option>';
            }
            if(!$cs) continue;
            foreach($cs as $c) {
                if($this->_attrs['selected'] == $c['col_id']) {
                    $str .= '<option selected="selected" value="'.$c['col_id'].'">' .$c['deep'].$c['name']. '</option>';
                }
                else {
                    $str .= '<option value="'.$c['col_id'].'">' .$c['deep'].$c['name']. '</option>';
                }
            }
        }
        $str .='</select>';
        return($str);

    }
}
?>